package com.qishon.jdk5;

/**
 * 泛型（泛型类）
 * see https://blog.csdn.net/s10461/article/details/53941091
 */
public class Generic<T> {
//public class Generic<T extends Number> {

    private T key;

    public Generic(T key) {
        this.key = key;
    }

    public T getKey() {
        return key;
    }

    //不是泛型方法
    public void showTemplateValue(Generic<T> num) {
        System.out.println(num.getKey());
    }

    public static void showValue(Generic<Number> num) {
        System.out.println(num.getKey().floatValue());
    }

    //此处’？’是类型实参，而不是类型形参，即是一种真实的类型
    public static void showWildMatchValue(Generic<?> num) {
        System.out.println(num.getKey());
    }

    //泛型方法
    public static <T> T genericMethod(Class<T> tClass) throws IllegalAccessException, InstantiationException {
        T instance = tClass.newInstance();
        return instance;
    }

    //TODO 泛型多个参数
    public static <T, K, J, M, S> K showOther(Generic<T> a) {
        return null;
    }

    //泛型方法与可变参数
    public static <T> void printMsg(T... args) {
        for (T t : args) {
            System.out.println(t);
        }
    }

    // PECS
    //https://www.zhihu.com/question/20400700

    //泛型上边界，即不能再上去了（父类）
    public static <T extends Number> T genericUpBorder(Generic<T> container) {
        return null;
    }

    //泛型下边界，即不能再下去了（子类）
    public <T> T genericDownBorder(Generic<? super T> generic) {
        return null;
    }
}